# Dickstein, Ho, and Mark (2023)
# This script runs the premium setting code that estimates equation 6.6 in the paper. 

# In order to run the premiums setting equation, the analyst must collect an estimate of the sum of $\hat{s}_{i,j}$\kappa_{i,j}c^{e}_{i,j}$ across households who have plan $j$ in their choice set. The script “predicted.R” completes this procedure. First, it collects $\hat{s}_{i,j}$ from the output of the relevant demand estimation procedure. Then, it estimates $c^{e}_{i,j}$ using a number of different methodologies. While the different methodologies were implemented for robustness (yielding fairly similar results), our preferred specification draws a cost from the household’s distribution of medical claims cost were the household to choose plan $j$, $(x_j+omega_i*x_j^2)*\lambda$. Then, this cost draw is winsorized at $8,937. We use winsorized cost draws in place of a direct estimate of $c^{e}_{i,j}$ in order to be able to winsorize and thus avoid observations with outlier costs in the premium setting regression. Last, it sums these variables $\hat{s}_{i,jc^{e}_{i,j}$ for all households and plans with the same $\kappa_{i,j}$. These objects are saved to be used in the premium setting equation. 
#To estimate the premium setting equation, we then run the script main.do. main.do sources from the other scripts in the folder. This code includes several robustness tests and ancillary analyses related to the premium setting analysis. The preferred specification is estimated using the paper_present function. 
# Note that the premium regression results are saved directly into the "tablesandfigures" folder.

Rscript predicted.r
stata -b main.do

# If you want to run the bootstrap estimation, use the runme in the bootstrap folder.
